package com.luatos.airtun.ws;

import javax.websocket.EndpointConfig;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Lang;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.plugins.mvc.websocket.AbstractWsEndpoint;
import org.nutz.plugins.mvc.websocket.WsHandler;

/**
 * 页面websocket入口
 *
 */
@ServerEndpoint(value = "/ws/echo2", configurator = NutWsConfigurator.class)
@IocBean
public class EchoEndpoint2 extends AbstractWsEndpoint {
	
	protected static final Log log = Logs.get();
	
	public WsHandler createHandler(Session session, EndpointConfig config) {
		return new EchoWsHandler2();
	}
	

    @OnMessage
    public void _onMesssageByteArray(Session session, byte[] msg) {
    	log.info("收到数据,并原样返回 " + Lang.fixedHexString(msg));
        sendBinary(session.getId(), msg);
    }
}
